package org.huang.sample03.demo01;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;

/**
 * @描述: 使用代码注册Servlet，Filter，Listener
 * @作者 Mr.Huang
 * @创建时间 2017-08-07
 * @版本: 1.0
 */

@SpringBootApplication
public class AppServer01 {

    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        return new ServletRegistrationBean(new MyServlet01(), "/servlet01/*");// ServletName默认值为首字母小写，即myServlet01
    }

    @Bean
    public FilterRegistrationBean filterRegistrationBean(){
        FilterRegistrationBean filterRegistrationBean  = new FilterRegistrationBean();
        filterRegistrationBean.setFilter(new MyFilter01());
        filterRegistrationBean.addUrlPatterns("/servlet01/*");//可以添加多个地址过滤
        return filterRegistrationBean;
    }

    @Bean
    public ServletListenerRegistrationBean servletListenerRegistrationBean(){
        ServletListenerRegistrationBean listenerRegistrationBean  = new ServletListenerRegistrationBean();
        listenerRegistrationBean.setListener(new MyListener01());
        return listenerRegistrationBean;
    }



    public static void main(String[] args) throws Exception {
        SpringApplication.run(AppServer01.class, args);
    }


}
